//
//  AboutViewController.m
//  Zaker
//
//  Created by lirui on 16/3/17.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AboutViewController.h"
#import <MessageUI/MessageUI.h>
@interface AboutViewController ()<MFMessageComposeViewControllerDelegate>

@end

@implementation AboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIImageView *ima = [[UIImageView alloc] initWithFrame:self.view.bounds];
    ima.image = [UIImage imageNamed:@"1fcc7e0b5b8353fa4b4925df365d8d32"];
    [self.view addSubview:ima];

//介绍内容
    
    UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 60, SCREEN_WIDTH - 120)];
    blackView.center = CGPointMake(self.view.center.x, self.view.center.y - 130);
    blackView.layer.cornerRadius = 20;
    blackView.alpha = 0.2;
    [self.view addSubview:blackView];
    
UILabel *contentLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, blackView.frame.size.width - 20, self.view.frame.size.height / 5)];
    contentLable.center = CGPointMake(self.view.center.x, self.view.center.y - 160);
contentLable.numberOfLines = 0;
contentLable.text = @"口袋新闻是包含新闻,视频,搞笑动图,专题话题的一款应有尽有的新闻App, <<口袋新闻>>在手,全球新闻装进口袋";
    contentLable.textColor = [UIColor whiteColor];
contentLable.font = [UIFont systemFontOfSize:19];
contentLable.layer.cornerRadius = 5;
contentLable.clipsToBounds = YES;
[self.view addSubview:contentLable];

//发短信按钮
UIButton *phone = [UIButton buttonWithType:UIButtonTypeCustom];
phone.frame = CGRectMake(0, blackView.frame.size.height, self.view.frame.size.width / 5 * 3, 40);
    phone.center = CGPointMake(self.view.center.x, phone.center.y);
[phone addTarget:self action:@selector(phoneAction) forControlEvents:UIControlEventTouchUpInside];
phone.layer.cornerRadius = 10;
phone.clipsToBounds = YES;
[phone setBackgroundColor:[UIColor redColor]];
[phone setTitle:@"推荐给好友" forState:UIControlStateNormal];
[self.view addSubview:phone];
}
#pragma mark - 发短信
-(void)phoneAction
{
    
    [self showMessageView:[NSArray arrayWithObjects:@"", nil] title:@"test" body:@"口袋新闻真的是一款不错的App,快去下载吧!"];
}
#pragma mark - 实现代理方法
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
            
            switch (result) {
                case MessageComposeResultSent:
                {
                    //弹窗
                    UIAlertController *promptAlert = [UIAlertController alertControllerWithTitle:@"提示" message:@"推荐成功" preferredStyle:UIAlertControllerStyleAlert];
                    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                        //
                        NSLog(@"确定");
                    }];
                    [promptAlert addAction:cancleAction];
                    [self presentViewController:promptAlert animated:YES completion:^{
                        
                    }];
                }
                    break;
                  case MessageComposeResultCancelled:
                    break;
                    case MessageComposeResultFailed:
                    break;
                default:
                    break;
            }
   
    
}
#pragma mark - 发送短信
-(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body
{
    if( [MFMessageComposeViewController canSendText] )
    {
        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
        controller.recipients = phones;
        controller.navigationBar.tintColor = [UIColor redColor];
        controller.body = body;
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:YES completion:nil];
        [[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题
          }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
                                                        message:@"该设备不支持短信功能"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil, nil];
        [alert show];

    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
